﻿using Finance.API.Write.Application.Command.ReceivablesManagementCommand;
using Finance.Domain;
using Finance.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Finance.API.Write.Controllers
{
    /// <summary>
    /// 应收管理
    /// </summary>
    //[Authorize]
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ReceivablesManagementController : ControllerBase
    {
        IMediator mediator;
        ILogger<ReceivablesManagementController> logger;

        public ReceivablesManagementController(IMediator mediator, ILogger<ReceivablesManagementController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }

        /// <summary>
        /// 应收管理添加
        /// </summary>
        /// <param name="receivablesManagement"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> AddReceivablesManagementCommand(AddReceivablesManagementCommand request)
        {
            try
            {
                
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("应收管理添加失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 应收管理逻辑删除
        /// </summary>
        /// <param name="ReceivablesManagementId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> DelReceivablesManagementCommand(int ReceivablesManagementId)
        {
            try
            {
                DelReceivablesManagementCommand request = new DelReceivablesManagementCommand()
                {
                    ReceivablesManagementId = ReceivablesManagementId
                };
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("应收管理逻辑删除失败" + ex.Message);
                throw;
            }
        }

        /// <summary>
        /// 应收管理修改
        /// </summary>
        /// <param name="receivablesManagement"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> UpdReceivablesManagementCommand(UpdReceivablesManagementCommand request)
        {
            try
            {
                 
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("应收管理修改失败" + ex.Message);
                throw;
            }
        }




















    }
}
